//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System.Collections.Generic;

namespace Microsoft.TridentWordAddIn.Presentation
{
    /// <summary>
    /// Class to indicate validation result and possible validation error messages
    /// </summary>
    public class ValidationResult
    {
        #region Fields

        private readonly List<string> messages = new List<string>();
        private bool isValid;

        #endregion

        #region Public Memebr functions

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationResult"/> class.
        /// </summary>
        public ValidationResult()
        { 
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationResult"/> class.
        /// </summary>
        /// <param name="isValid">if set to <c>true</c> [is valid].</param>
        public ValidationResult(bool isValid)
        {
            this.isValid = isValid;
        }

        /// <summary>
        /// Gets a value indicating whether validation subject is valid or not.
        /// </summary>
        /// <value><c>true</c> if this subject is valid; otherwise, <c>false</c>.</value>
        public bool IsValid
        {
            get { return this.isValid; }
        }

        /// <summary>
        /// Gets the messages.
        /// </summary>
        /// <value>The messages.</value>
        public IList<string> Messages
        {
            get { return this.messages; }
        }

        /// <summary>
        /// Merges the specified validation result. 
        /// </summary>
        /// <param name="validationResult">The validation result to merge into the the current instance.</param>
        internal void Merge(ValidationResult validationResult)
        {
            if (!validationResult.isValid)
            {
                this.isValid = false;
            }

            foreach (string message in validationResult.messages)
            {
                this.messages.Add(message);
            }
        }

        /// <summary>
        /// Gets the messages concatenated to one string instance.
        /// </summary>
        /// <returns>the <c>that is the concatenation of all messages separated by new 
        /// line and return (\n\r)</c></returns>
        internal string GetMessage()
        {
            string[] array = new string[this.messages.Count];
            this.messages.CopyTo(array, 0);
            return string.Join("\n\r", array);
        }

        #endregion
    }
}
